package hng.service.admin.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import hng.dto.NavDTO;
import hng.mapper.BannerMapper;
import hng.model.BannerDO;
import hng.model.NavDO;
import hng.mapper.NavMapper;
import hng.service.admin.NavService;
import hng.service.admin.NavService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import hng.util.JsonData;
import lombok.extern.slf4j.Slf4j;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * <p>
 * 导航栏 服务实现类
 * </p>
 *
 * @author 告白
 * @since 2024-06-27
 */

@Service

public class NavServiceImpl extends ServiceImpl<NavMapper, NavDO> implements NavService {

    @Autowired(required = false)
    private NavMapper navMapper;
    @Autowired(required = false)
    private BannerMapper bannerMapper;

    /**
     * 添加导航栏
     * **/
    @Override
    public void add(NavDTO navDTO) {
        NavDO navDO = new NavDO();
        BeanUtils.copyProperties(navDTO,navDO);
        navMapper.insert(navDO);
    }
    /**
     * 删除导航栏
     * **/
    @Override
    public void del(Integer id) {
        int row = navMapper.delete(new LambdaQueryWrapper<NavDO>()
                .eq(NavDO::getId,id)
        );
    }
    /**
     * 更新导航栏
     * **/
    @Override
    public void update(NavDTO navDTO) {
        NavDO navDO = new NavDO();
        BeanUtils.copyProperties(navDTO,navDO);
        int row = navMapper.update(navDO,new  LambdaQueryWrapper<NavDO>()
                .eq(NavDO::getId,navDTO.getId())
        );
    }
    /**
     * 查询所有导航栏
     * **/
    @Override
    public List<NavDO> navList() {
        List<NavDO> navDOList = navMapper.selectList(null);
        return navDOList;
    }
}
